package com.tfswx.springboothomework.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@RestController
@RequestMapping("/multiplication")
public class MultiPlicationController {

    @GetMapping("/table")
    public void printMultiplicationTable(HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("gbk");
        PrintWriter writer = response.getWriter();
        for (int i = 1; i <= 9 ; i++) {
            writer.write("<p>");
            for(int j = 1;j <= i;j++){
                writer.printf("%d*%d = %2d ", i, j, i*j);
            }
            writer.write("</p>");
        }

        writer.write("<br>");

        for (int i = 9; i >=1 ; i--) {
            writer.write("<p>");
            for(int j = i;j >= 1; j--){
                writer.printf("%d*%d = %2d ", i, j, i*j);
            }
            writer.write("</p>");
        }
    }

    public static void main(String[] args) {
        // 修改文件名后的修改
        // limm1修改了
        // limm2修改了

        // 2修改的内容
    }
}
